<template>
  <div class="flexContent">
    <!-- 门店预付款 -->
    <div class="searchBox">

      <el-form class="demo-form-inline" label-position="left" label-width="auto" @submit.native.prevent>
        <div class="serFlexBox">
          <div class="inputBox">
            <el-row :gutter="12" style="display: flex;flex-wrap: wrap;">
              <el-col :xs="12" :sm="12" :md="12" :lg="8" :xl="6">
                <el-form-item label="门店名称">
                  <el-input v-clearEmoji v-model.trim="name" clearable style="width: 95%" placeholder="门店名称"
                    @keyup.enter.native="searchFn" />
                </el-form-item>
              </el-col>
            </el-row>
          </div>
          <div class="btnBox">
            <el-button @click.stop="searchFn" class="searchBtn" icon="el-icon-search">搜索</el-button>
            <el-button @click.stop="emptyFn" class="resetBtn" icon="el-icon-refresh-right">重置</el-button>
          </div>
        </div>
      </el-form>
    </div>
    <!-- <el-button class="addBtn" @click="addFn">新增</el-button> -->
    <div class="table" id="tableBox" v-height>
      <div style="flex:1;">
        <vxe-table :column-config="{ resizable: true }" border class="tablebox" ref="xTable1"
          :row-config="{ isHover: true }" :scroll-y="{ enabled: true, gt: 21 }" style="width: 100%" height="100%"
          size="medium" align="center">
          <vxe-column type="seq" width="80" title="序号" />
          <vxe-column field="storeName" title="门店名称" :min-width="elTableAdaptationWidth('storeName', storeAdvanceList)" />
          <vxe-column field="balance" title="剩余余额（元）" min-width="150" />
          <vxe-column field="addCount" title="加款次数" min-width="100" />
          <vxe-column title="操作" fixed="right" width="150"
            v-if="$showFn(['storeAdvance_addmoney', 'storeAdvance_detail'])">
            <template v-slot="{ row }">
              <el-button type="text" @click.stop="add(row)" v-has="'storeAdvance_addmoney'">加款</el-button>
              <el-button type="text" style="margin-right: 5px" @click.stop="detail(row)"
                v-has="'storeAdvance_detail'">详情</el-button>
            </template>
          </vxe-column>
        </vxe-table>
      </div>
      <div class="paginationBox">
        <el-pagination :current-page="page.pageNum" background :page-sizes="$pageSizes" :page-size="page.pageSize"
          layout="total,->, sizes, prev, pager, next, jumper" :total="page.total" @size-change="handleSizeChange"
          @current-change="handleCurrentChange" />
      </div>
    </div>
  </div>
</template>

<script>
import { getStoreAdvanceList, genericGoodsDelete } from "@/api/genericGoods";
export default {
  name: "GenericGoodsInfo",
  data() {
    return {
      storeAdvanceList: [],
      name: "",
      isSearch: false,
      page: {
        pageNum: 1,
        pageSize: 20,
        total: 0,
      },
    };
  },
  created() {
    this.getStoreAdvanceList();
  },
  methods: {
    async getStoreAdvanceList() {
      if (!this.isSearch) {
        this.name = "";
      }
      const res = await getStoreAdvanceList({
        ...this.page,
        storeName: this.name,
      });
      if (res.code === 200) {
        const data = res.data;
        console.log(res, "res");
        this.storeAdvanceList = data.list;
        this.page.pageSize = data.pageSize;
        this.page.pageNum = data.pageNum;
        this.page.total = data.total;
        const $table = this.$refs.xTable1
        $table.loadData(this.storeAdvanceList);
        console.log("列表", this.storeAdvanceList);
      } else {
        // this.$message.error(res.msg);
      }
    },
    async searchFn(sKeywords) {
      this.page = {
        pageNum: 1,
        pageSize: 20,
        total: 0,
      };

      this.isSearch = true;
      this.getStoreAdvanceList();
    },
    emptyFn() {
      this.page = {
        pageNum: 1,
        pageSize: 20,
        total: 0,
      };
      this.isSearch = false;
      this.name = "";
      this.getStoreAdvanceList();
    },
    add(row) {
      this.$router.push({
        path: "storeAdvanceAdd",
        query: {
          id: row.id,
        },
      });
    },
    detail(row) {
      this.$router.push({
        path: "storeAdvanceDetail",
        query: {
          id: row.id,
        },
      });
    },
    // 获取条数改变
    handleSizeChange(val) {
      this.page.pageSize = val;
      this.page.pageNum = 1;
      this.getStoreAdvanceList();
    },
    // 获取页数改变
    handleCurrentChange(val) {
      this.page.pageNum = val;
      this.getStoreAdvanceList();
    },
  },
};
</script>

<style scoped lang="scss"></style>
